<!--计量单位选择框-->
<template>
  <div>
    <BasicModal v-bind="$attrs" @register="register" :title="modalTitle" width="800px" @ok="handleOk" destroyOnClose @visible-change="visibleChange">
      <BasicTable
        :columns="columns"
        v-bind="config"
        :useSearchForm="true"
        :formConfig="formConfig"
        :api="psProductionArrangementPlansDistribute"
        :searchInfo="searchInfo"
        :rowSelection="rowSelection"
        :indexColumnProps="indexColumnProps"
      ></BasicTable>
    </BasicModal>
  </div>
</template>
<script lang="ts">
import { defineComponent, ref, unref } from 'vue';
import { BasicModal, useModalInner } from '/@/components/Modal';
import { psProductionArrangementPlansDistribute } from '/@/views/plan/assemblyScheduling/psProductionArrangementPlans/PsProductionArrangementPlans.api';
import { createAsyncComponent } from '/@/utils/factory/createAsyncComponent';
import { useSelectBiz } from '/@/components/Form/src/jeecg/hooks/useSelectBiz';
import { selectProps } from '/@/components/Form/src/jeecg/props/props';
import { useAttrs } from '/@/hooks/core/useAttrs';
import { render } from '/@/utils/common/renderUtils';

export default defineComponent({
  name: 'CalculateSelectModal',
  components: {
    //此处需要异步加载BasicTable
    BasicModal,
    BasicTable: createAsyncComponent(() => import('/@/components/Table/src/BasicTable.vue'), {
      loading: true,
    }),
  },
  props: {
    ...selectProps,
    //选择框标题
    modalTitle: {
      type: String,
      default: '选择前工序排产计划',
    },
    multiple: {
      type: Boolean,
      default: false,
    },
  },

  emits: ['register', 'getSelectResult'],
  setup(props, { emit }) {
    //注册弹框
    const [register, { closeModal }] = useModalInner();
    const attrs = useAttrs();
    //表格配置
    const config = {
      canResize: false,
      bordered: true,
      size: 'small',
      rowKey: unref(props).rowKey,
      labelKey: 'name',
      isRadioSelection: !(props.multiple == true) ?? true,
    };
    const getBindValue = Object.assign({}, unref(props), unref(attrs), config);
    const [{ rowSelection, indexColumnProps, visibleChange, getSelectResult }] = useSelectBiz(psProductionArrangementPlansDistribute, getBindValue);

    const searchInfo = ref(props.params);
    //查询form
    const formConfig = {
      labelWidth: 100,
      baseColProps: {
        xs: 8,
        sm: 8,
        md: 8,
        lg: 8,
        xl: 8,
        xxl: 8,
      },
      schemas: [
      {
          label: '是否总装工艺',
          field: 'finalAssembly',
          component: 'Input',
          defaultValue: 0,
          show:false,
          colProps: {
            span: 6,
          },
        },
        {
          label: '订单编号',
          field: 'orderNumber',
          component: 'Input',
          colProps: {
            span: 6,
          },
        },
        // {
        //   label: '工作中心',
        //   field: 'workCenter',
        //   component: 'Input',
        //   colProps: {
        //     span: 6,
        //   },
        // },
        {
          label: '排产开始日期',
          field: 'lineDateStart',
          component: 'DatePicker',
          componentProps: {
            showTime: false,
            valueFormat: 'YYYY-MM-DD',
          },
          colProps: {
            span: 6,
          },
        },
        {
          label: '排产结束日期',
          field: 'lineDateEnd;',
          component: 'DatePicker',
          componentProps: {
            showTime: false,
            valueFormat: 'YYYY-MM-DD',
          },
          colProps: {
            span: 6,
          },
        },
      ],
    };
    //   useModal((data: any) => {
    //     console.log(data);
    //   });
    //定义表格列
    const columns = [
      {
        title: '排产日期',
        dataIndex: 'createTime',
        width: 40,
        align: 'left',
      },
      {
        title: '订单编号',
        dataIndex: 'orderNumber',
        width: 40,
      },
      {
        title: '行号',
        dataIndex: 'rowNum',
        width: 40,
      },
      {
        title: '产品编码',
        dataIndex: 'materialCode',
        width: 40,
      },
      {
        title: '产品名称',
        dataIndex: 'materialName',
        width: 40,
      },
      {
        title: '排产数量',
        dataIndex: 'totalQuantity',
        width: 40,
      },
      {
        title: '上线日期',
        dataIndex: 'lineDate',
        width: 40,
      },
      {
        title: '工艺',
        dataIndex: 'process',
        width: 40,
      },
    ];

    /**
     * 确定选择
     */
    function handleOk() {
      getSelectResult((options, values) => {
        //回传选项和已选择的值
        emit('getSelectResult', options, values);
        //关闭弹窗
        closeModal();
      });
    }

    return {
      config,
      handleOk,
      searchInfo,
      register,
      indexColumnProps,
      visibleChange,
      psProductionArrangementPlansDistribute,
      formConfig,
      getBindValue,
      columns,
      rowSelection,
    };
  },
});
</script>